package com.heng.restTemplate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class TestService implements CommandLineRunner {

    // 注入 RestTemplate
    @Autowired
    private RestTemplate restTemplate;

    public String callTestB() {
        // 接口地址
        String url = "http://localhost:8401/testA";
        
        try {
            // 发送 GET 请求，返回字符串类型的响应
//            String response = restTemplate.getForObject(url, String.class);
//            System.out.println("接口响应：" + response);
            return "response";
        } catch (Exception e) {
            System.err.println("请求失败：" + e.getMessage());
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public void run(String... args) throws Exception {
//        while (true) {
//            Thread.sleep(100);
////            callTestB();
//        }
    }
}